//
//  LSSoundPlayer.m
//  听说弱点强化训练
//
//  Created by 盛超 on 2018/11/7.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "LSSoundPlayer.h"

@implementation LSSoundPlayer

- (instancetype)initWithSound:(KZSoundType)type {
    if (self = [super init]) {
        
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        [audioSession setActive:YES error:nil];
        NSError * error;
        BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&error];
        if(!success)
        {
            NSLog(@"error doing outputaudioportoverride - %@", [error localizedDescription]);
        }
        NSString *soundPath = [[NSBundle mainBundle] pathForResource:[self soundName:type] ofType:@"caf"];
        NSData *data = [NSData dataWithContentsOfFile:soundPath];
        
        self = [super initWithData:data error:&error];
        [self prepareToPlay];
        [self play];
    }
    
    return self;
}

- (NSString *)soundName:(KZSoundType)type {
    
    return @[@"回答正确",
             @"回答错误",
             @"结果-成功",
             @"结果-失败",
             @"首页分析",
             @"三关",
             @"翻页"
             ][(int)type];
}


@end
